﻿#region references
using System;
#endregion

namespace IcaGames.Database
{
    public static class Cast
    {
        /*
         * Function to cast specified data to an Integer.
         * 
         * @param
         * data: The data to cast.
         * 
         * @returns
         * The casted Integer on correct data.
         * A 0 value on incorrect data.
         */
        public static int CastToInteger(object data)
        {
            if (data != DBNull.Value)
            { return Convert.ToInt32(data); }
            else
            { return 0; }
        }

        /*
         * Function to cast specified data to a String.
         * 
         * @param
         * data: The data to cast.
         * 
         * @returns
         * The casted String on correct data.
         * An empty String on incorrect data.
         */
        public static string CastToString(object data)
        {
            if (data != DBNull.Value)
            { return data.ToString(); }
            else
            { return string.Empty; }
        }

        /*
         * Function to cast specified data to a decimal.
         * 
         * @param
         * data: The data to cast.
         * 
         * @returns
         * The casted decimal on correct data.
         * A 0 value on incorrect data.
         */
        public static decimal CastToDecimal(object data)
        {
            if (data != DBNull.Value)
            { return Convert.ToDecimal(data); }
            else
            { return 0; }
        }

        /*
         * Function to cast specified data to DateTime.
         * 
         * @param
         * data: The data to cast.
         * 
         * @returns
         * The created DateTime on correct data.
         * A DateTime value "0-0-0000" on incorrect data.
         */
        public static DateTime CastToDateTime(object data)
        {
            if (data != DBNull.Value)
            { return Convert.ToDateTime(data); }
            else
            { return DateTime.MinValue; }
        }
    }
}
